import { request } from '@umijs/max';
import { ArchiveType, ArchiveRecord } from '@/types/prefiling/onlineCollecting';
/**
 * 功能：获取档案类型树
 **/
export async function queryArchiveTypes(params?: any) {
    return request('/admin/fileType/getTreeByRoleIds', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}

/**
 * 功能：获取页面的按钮
 **/
export async function getMenuButton(params?: any) {
    return request('/menu/button/getByMenuId', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}


/**
 * 功能：获取档案明细信息
 * 参数：typeCode-档案类型,arrangeDimension-管理维度，fullId-全宗id，pageLink-界面环节
 **/
export async function getDynamicData(params?: any) {
    return request('/admin/fileField/queryBillFieldOfDisplayQuery', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}

/**
 * 功能：获取配置的查询条件数据
 * 参数：typeCode-档案类型,templateType-管理维度，fullId-全宗id
 **/
export async function getQueryDynamicData(params?: any) {
    return request('/prefiling/offlineCollecting/toQueryField', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}


/**
 * 功能：获取排序字段
 * 参数：typeCode-档案类型,arrangeDimension-管理维度，fullId-全宗id
 **/
export async function getSortFieldData(params?: any) {
    return request('/sortField/select', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}

/**
 * 功能：获取分组信息字段
 **/
export async function getGroupInfoData(params?: any) {
    return request('/archiveNo/config/getArchiveConfig', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
} 

/**
 * 功能：表格数据接口
 **/
export async function fetchList(params?: any) {
    return request('/prefiling/onlineCollecting/page', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 




/**
 * 功能：表格新增数据接口
 **/
export async function getAddList(params?: any) {
    return request('/admin/fileField/queryBillFieldOfDisplayInput', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 



/**
 * 功能：表格修改数据接口
 **/
export async function getEditList(params?: any) {
    return request('/admin/fileField/queryBillFieldOfDisplayEdit', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 

/**
 * 功能：生成档号
 **/
export async function createNum(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/arrangeCatalog/createNum', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}

/**
 * 功能：清除档号
 **/
export async function cleanNum(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/arrangeCatalog/cleanNum', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}


/**
 * 功能：上传附件
 **/
export async function uploadFile(fullId:any,file:File) {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('fullId', fullId || '');
    // formData.append('typeCode', typeCode || '');
    return request<API.Result>('/admin/file/upload', {
        method: 'POST',
        data: formData,
    });
}

/**
 * 功能：数据字典查询
 **/
export async function dictData(params?: any) {
    return request('/admin/dict/getType', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 

/**
 * 功能：动态下拉框接口查询
 **/
export async function dynamicDictSelectData(url:string,params?: any) {
    return request("/"+url, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 

/**
 * 功能：表格修改获取数据接口
 **/
export async function getEditInfo(params?: any) {
    return request('/prefiling/onlineCollecting/edit', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        params,
    });
} 

/**
 * 功能：新增/编辑保存
 **/
export async function saveAdd(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/prefiling/onlineCollecting/save', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}

export async function viewAttachment(params:any): Promise<Blob> {
    return request('/prefiling/onlineCollecting/viewAttachment1', {
      method: 'GET',
      params: params,
      responseType: 'blob', // 关键配置，指定响应类型为blob
    });
}

// 批量锁定/解锁档案
export async function batchLock(params: {
    id: string;
    typeCode: string;
    arrangeDimension: string;
    lockFlag: string;
    fullId: string;
  }) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
      formData.append(key, String(value));
    });
    return request('/prefiling/onlineCollecting/batchLock', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: formData.toString()
    });
  }
  
  // 批量删除档案附件
  export async function removeFileById(params: {
    ids: string;
    arrangeDimension: string;
    typeCode: string;
    fullId: string;
  }) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
      formData.append(key, String(value));
    });
    return request('/prefiling/onlineCollecting/removeFileById', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: formData.toString()
    });
  }
  
  // 批量删除档案
  export async function batchDelete(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
      formData.append(key, String(value));
    });
    return request('/prefiling/onlineCollecting/batchDelete', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: formData.toString()
    });
  }

/**
 * 功能：加入暂存架
 **/
export async function saveScratchShelf(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/utilization/collect/saveScratchShelf', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}


/**
 * 功能：移交申请
 **/
export async function applySubmit(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/utilization/transfer/applySubmit', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}

/**
 * 功能：获取下个审批人信息
 **/
export async function getNextApproves(params: any) {
    return request<API.Result>('/flow/getNextApproves', {
        method: 'Get',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8',
        },
        params
    });
}


/**
 * 功能：归入整编
 **/
export async function batchSubmit(params: any) {
    const formData = new URLSearchParams();
    Object.entries(params).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request<API.Result>('/prefiling/onlineCollecting/batchSubmit', {
        method: 'Post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: formData.toString()
    });
}
